package miao.demo;

import miao.demo.dao.BookDao;
import miao.demo.service.BookService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AppForLifeCycle {
    public static void main(String[] args) {
        //ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        //ctx.close(); //暴力关闭 会报错
        ctx.registerShutdownHook();
        BookDao bookDao = (BookDao) ctx.getBean("bookDao");
        bookDao.save();
        //BookService bookService = (BookService) ctx.getBean("bookService");
        //bookService.save();
        //关闭容器
        ctx.close();


    }
}
